package com.appkubes.mall.admin.application.goods.sku.controller;

import com.appkubes.common.Response;
import com.appkubes.mall.admin.application.base.BaseController;
import com.appkubes.mall.admin.application.goods.sku.entity.vo.TypeVO;
import com.appkubes.mall.admin.application.goods.sku.service.SpecificAttributeService;
import com.appkubes.mall.admin.application.goods.sku.service.SpecificTypeService;
import com.appkubes.mall.admin.application.goods.sku.service.impl.SpecificAttributeServiceImpl;
import com.appkubes.mall.admin.application.goods.sku.service.impl.SpecificTypeServiceImpl;
import com.appkubes.mall.admin.config.camel.RequestModel;
import com.appkubes.mall.core.po.MallSpecificType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api("多规格类型")
@RestController
@RequestMapping("/sass_admin/Sspecifictype")
public class SpecificTypeController extends BaseController {

    @Autowired
    SpecificTypeService specificTypeService;

    @Autowired
    SpecificAttributeService specificAttributeService;

    @ApiOperation("增加规格")
    @PostMapping("add")
    public Response add(@RequestModel TypeVO typeVo) {
        MallSpecificType mallSpecificType = new MallSpecificType();
        BeanUtils.copyProperties(typeVo, mallSpecificType);
        specificTypeService.add(mallSpecificType);
        return Response.success(mallSpecificType);
    }

    @ApiOperation("删除规格")
    @PostMapping("del")
    public Response del(@RequestParam(defaultValue = "") String key) {
        specificAttributeService.delByParentKey(key);
        return Response.success(specificTypeService.del(key));
    }
}
